package com.juneyao.bigdata.service.impl;

import com.alibaba.fastjson.JSONObject;

import com.juneyao.bigdata.domain.ResultParam;
import com.juneyao.bigdata.domain.SetGroupVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author quanbiao
 * @date 2018-06-14
 */
public class SetLogicTreatmentServiceImpl {

    private Logger logger = LoggerFactory.getLogger("SetLogicTreatmentServiceImpl");

    public void setJsonTreatment(String jsonStr, RestTemplate restTemplate, String url_send){
        //根据传入的json解析成对象
        SetGroupVo setGroupVo = JSONObject.parseObject(jsonStr, SetGroupVo.class);
        //获取pid为0的，然后获取id，作为crowdId
        String crowdId = setGroupVo.getListCmpPeoplegroupVo().stream()
                .filter(item -> item.getPid().equals("0")).findFirst().get().getId();

        getUserIdsByLabels(crowdId, restTemplate, url_send);
    }

    /**
     * 根据标签集合获取人员
     * @param crowdId
     * @param restTemplate
     * @param url_send
     */
    public void getUserIdsByLabels(String crowdId, RestTemplate restTemplate, String url_send){

       //集合处理后调用java的接口,告诉前端集合已处理完成
       Map<String,Object> map = new HashMap<>(16);
       map.put("msg",crowdId);
       map.put("status", "200");
       restTemplate.postForObject(url_send, map, ResultParam.class);
       logger.info("集合预处理完成回调完成");

    }


}
